package com.lishe.lishe.lishe.utils;

import android.view.View;
import android.view.animation.LinearInterpolator;

import com.nineoldandroids.animation.ObjectAnimator;
import com.nineoldandroids.animation.ValueAnimator;

/**
 * Created by yang on 2018/1/16.
 * 属性动画工具类
 */

public class AnimatorUtils {
    // 旋转
    static String rotationX = "rotationX";
    static String rotationY = "rotationY";
    // 渐变
    static String alpha = "alpha";
    // 缩放
    static String scale = "scale";
    static String scaleX = "scaleX";
    static String scaleY = "scaleY";
    // 移动
    static String translationX = "translationX";
    static String translationY = "translationY";

    public static void AnimatorRotationX(View view) {
        ObjectAnimator.ofFloat(view, rotationX, 0f, 360f)
                .setDuration(1000)
                .start();
    }

    public static ObjectAnimator AnimatorRotation(View view) {
        ObjectAnimator annimator = ObjectAnimator.ofFloat(view, "rotation", 0f, 360f)
                .setDuration(5000);
        //设置动画执行次数，INFINITE 为无限循环动画，需要注意属性动画的无限循环动画会造成内存泄漏，需要在特定情况下停止动画
        annimator.setRepeatCount(ValueAnimator.INFINITE);
        annimator.setRepeatMode(ValueAnimator.RESTART);
        annimator.setInterpolator(new LinearInterpolator());
        return annimator;
    }
}
